package com.groot.common.util;

import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.groot.medical.entity.Pay;

public class ExcelUtils {
	//查询已认证用户列表
	public static XSSFWorkbook exportContacts(List<Pay> list)
	throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
	XSSFWorkbook xssfWorkbook = null;
	String sheetName = "已认证用户列表";
	xssfWorkbook = createExcelFile(list, sheetName);
	return xssfWorkbook;
}

	//已认证数据生成EXCEL
	public static XSSFWorkbook createExcelFile(List<Pay> list, String sheetName)throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
	// 创建新的Excel工作簿
	XSSFWorkbook workbook = new XSSFWorkbook();
	// 在Excel工作簿中建一工作表，其名为缺省值, 也可以指定Sheet名称
	XSSFSheet sheet = workbook.createSheet(sheetName);
	XSSFRow row = sheet.createRow(0);
	XSSFCell cell = row.createCell(0);
	cell.setCellValue("序号");
	cell = row.createCell(1);
	cell.setCellValue("农合证号");
	cell = row.createCell(2);
	cell.setCellValue("家庭编号");
	cell = row.createCell(3);
	cell.setCellValue("身份证号");
	cell = row.createCell(4);
	cell.setCellValue("姓名");
	cell = row.createCell(5);
	cell.setCellValue("付款金额");
	cell = row.createCell(6);
	cell.setCellValue("付款时间");
	cell = row.createCell(7);
	cell.setCellValue("付款年份");
	cell = row.createCell(8);
	cell.setCellValue("操作员");
	cell = row.createCell(9);
	cell.setCellValue("发票号");
	
	SimpleDateFormat fs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	for (int i = 0; i < list.size(); i++) {
	row = sheet.createRow(i+1);
	row.createCell(0).setCellValue(list.get(i).getId());
	row.createCell(1).setCellValue(list.get(i).getFarmingCardCord());
	row.createCell(2).setCellValue(list.get(i).getFamilyCode());
	row.createCell(3).setCellValue(list.get(i).getIdcardCode());
	row.createCell(4).setCellValue(list.get(i).getName());
	row.createCell(5).setCellValue(list.get(i).getPayMoney());
	row.createCell(6).setCellValue(fs.format(list.get(i).getPayTime()));
	row.createCell(7).setCellValue(list.get(i).getCurretYear());
	row.createCell(8).setCellValue(list.get(i).getOperater());
	row.createCell(9).setCellValue(list.get(i).getVoucherId());
	}
	return workbook;
	}
}

